package com.zb.network.controller;


import com.zb.annotation.SystemLog;
import com.zb.constant.OperationLogModuleType;
import com.zb.constant.OperationLogType;
import com.zb.result.PageUtil;
import com.zb.result.Result;
import com.zb.service.ZjNetworkEmpService;
import com.zb.utils.TokenUtil;
import com.zb.vo.NetworkEmpSelectVo;
import com.zb.vo.NetworkEmpVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 网点人员表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2023-10-18
 */
@Api(tags = "服务商人员类接口")
@RestController
@RequestMapping("/network/emp")
public class ZjNetworkEmpController {
    @Resource
    private ZjNetworkEmpService networkEmpService;

    @SystemLog(moduleType = OperationLogModuleType.NETWORK_TYPE, type = OperationLogType.INSERT_UPDATE, remark = "服务区域-服务商人员 - 新增或修改服务商人员")
    @ApiOperation("新增或修改服务商人员")
    @PostMapping("/save")
    public Result save(HttpServletRequest request, @RequestBody @Valid NetworkEmpVo networkEmpVo) {
        //判断是否为新对象，创建新对象时将员工等级设置为普通师傅
        if(networkEmpVo.getNetworkEmpLevelId() == null){networkEmpVo.setNetworkEmpLevelId(1914494057544290306L);}      //1914494057544290306 为普通师傅id
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        networkEmpService.save(custAccId, networkEmpVo);
        return Result.success(null == networkEmpVo.getId()? "新增服务人员成功" : "修改服务人员成功");
    }

    @ApiOperation("获取服务人员列表")
    @PostMapping("/getList")
    public Result getList(HttpServletRequest request, @RequestBody NetworkEmpSelectVo selectVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success("获取服务人员列表成功").data(networkEmpService.getList(custAccId, selectVo));
    }

}
